import Mock from 'mockjs'

function getList() {
  const json = {code: 200, success: true, msg: '操作成功'};
  const list = [];
  list.push(
    {
      id: '1',
      name: '数据迁移B-D',
      log: '******',
      status: 1,
      errMsg: "",
      createTime: "2019-4-26"
    },
    {
      id: '2',
      name: '数据迁移A-D',
      log: '*******',
      status: 0,
      errMsg: "数据库连接失败",
      createTime: "2019-4-26"
    },
  );
  json.data = {
    total: 2,
    size: 10,
    current: 1,
    searchCount: true,
    pages: 1,
    records: list,
  };
  return json;
}

function getDetail() {
  const json = {code: 200, success: true, msg: '操作成功'};
  let detail = {
    id: '2',
    name: '数据迁移A-D',
    log: '*******',
    status: 0,
    errMsg: "数据库连接失败",
    createTime: "2019-4-26"
  };
  json.data = detail;
  return json;
}

function getOverviewList() {
  const json = {code: 200, success: true, msg: '操作成功'};
  const list = [];
  list.push(
    {
      id: '1258205188337991681',
      name: 'test1',
      runNum: '******',
      runningNum: 1,
      successNum: "",
      errorNum: "2019-4-26",
      lastSuccessTime: "2020-5-11 9:48",
      lastErrorTime: "2020-5-11 9:50"
    },
  );
  json.data = {
    total: 2,
    size: 10,
    current: 1,
    searchCount: true,
    pages: 1,
    records: list,
  };
  return json;
}


export default ({mock}) => {
  if (!mock) return;
  Mock.mock('/api/kettle/tasklog/list', 'get', () => {
    return getList();
  })
  Mock.mock(/\/api\/kettle\/tasklog\/\d+/, 'get', () => {
    return getDetail();
  })
  Mock.mock('/api/kettle/tasklog/overview_list', 'get', () => {
    return getOverviewList();
  })
}
